package com.xyzwps.paimon.katheryne.modules.user;

import com.xyzwps.paimon.katheryne.commons.dbmapper.RowMappers;
import io.helidon.dbclient.DbExecute;

import java.util.Objects;
import java.util.Optional;

public class UserAccountRepository {

    private final DbExecute db;

    public UserAccountRepository(DbExecute db) {
        this.db = Objects.requireNonNull(db);
    }

    public Optional<UserAccount> findByUserId(Long userId) {
        var sql = """
                select user_id, phone, locked, disabled, create_time, update_time
                from user_account
                where user_id = :id
                """;
        var rows = db.createQuery(sql)
                .addParam("id", userId)
                .execute();
        return rows.map(it -> RowMappers.to(it, UserAccount.class)).findFirst();
    }
}
